import threading
import time


class Main(threading.Thread):
    def __init__(self, name, thread_id):
        super().__init__()  # 继承父类初始化方法
        self.thread_id = thread_id
        self.name = name
        self.spider_url = 'http://564ck.cc/'
        pass

    def run(self):
        total = 10
        while total:  # 假设总任务次数为1000
            time.sleep(1)
            print("\n开始线程：" + self.name + "===")
            total -= 1

if __name__ == '__main__':
    start_time = time.time()
    print('这是主线程：', threading.current_thread().name)

    thread_list = []
    for i in range(100):  # 100个线程同时启动
        t = Main(i, 'thread-' + str(i))
        thread_list.append(t)
    for t in thread_list:  # 100个线程同时启动
        t.setDaemon(True)
        t.start()
    for t in thread_list:  # 100个线程同时启动
        t.join()  # 主线程等待子线程执行完毕后才退出
    print('主线程结束！', threading.current_thread().name)
    print('主线程结束，一共用时：', time.time() - start_time)
